package demo5;

public class MyQueue {
    static class ListNode {
        public ListNode prev;
        public ListNode next;
        public int val;
        public ListNode(int val) {
            this.val = val;
        }

    }
    public ListNode head;
    public ListNode last;
    public int usedSize = 0;
    public void offer(int data) {
        ListNode node = new ListNode(data);
        if(last == null) {
            head = last = node;
        }else {
            node.prev = last;
            last.next = node;
            last = last.next;
        }
        usedSize++;
    }
    public int poll() {
        if(head == null) {
            throw new NullException("队列为空");
        }
        int x = head.val;
        head = head.next;
        if(head != null) {
            head.prev = null;
        }
        usedSize--;
        return x;
    }
    public int peek() {
        if(head == null) {
            throw new NullException("队列为空");
        }
        return head.val;
    }
    public boolean isEmpty() {
        return usedSize == 0;
    }
}
